#include "InvokeInstructionImp.h"

std::shared_ptr<Command> InvokeTUI::cmd;
std::shared_ptr<Command> InvokeTUIBatch::cmd;

void InitInvokeInstructionMap(std::shared_ptr<Command> &tuiCmd, std::shared_ptr<Command> &tuiBatchCmd)
{
    InvokeInstruction::RegisterInstruction(std::shared_ptr<InvokeInstruction>(new InvokeHelpCmd));
    InvokeInstruction::RegisterInstruction(std::shared_ptr<InvokeInstruction>(new InvokeDemoCmd));
    InvokeInstruction::RegisterInstruction(std::shared_ptr<InvokeInstruction>(new InvokeTUI));
    InvokeInstruction::RegisterInstruction(std::shared_ptr<InvokeInstruction>(new InvokeTUIBatch));
    InvokeTUI::SetCommand(tuiCmd);
    InvokeTUIBatch::SetCommand(tuiBatchCmd);
}

InvokeHelpCmd::InvokeHelpCmd()
{
    this->instName = "h";
    this->helpInfo = "print help information";
    this->argsInfo = "";
}

void InvokeHelpCmd::Execute(std::vector<std::string> &args)
{
    std::string helpInfo;
    helpInfo += "========== HELP ==========\n";
    helpInfo += "Instruction Info:\n";
    for (const auto &item : InvokeInstruction::invokeInstMap) {
        helpInfo += item.second->GetHelp() + "\n";
    }
    this->logger->Print(helpInfo);
}

InvokeDemoCmd::InvokeDemoCmd()
{
    this->instName = "d";
    this->helpInfo = "DemoCmd";
    this->argsInfo = "";
}

void InvokeDemoCmd::Execute(std::vector<std::string> &args)
{
    this->logger->Info("this is demo\n");
    for (const auto &item : args) {
        this->logger->Info(item + "\n");
    }
}

InvokeTUI::InvokeTUI()
{
    this->instName = "t";
    this->helpInfo = "TUI";
    this->argsInfo = "";
}

void InvokeTUI::Execute(std::vector<std::string> &args)
{
    if (cmd != nullptr) {
        cmd->Do(args);
    }
}

void InvokeTUI::SetCommand(std::shared_ptr<Command> &cmd)
{
    InvokeTUI::cmd = cmd;
}

InvokeTUIBatch::InvokeTUIBatch()
{
    this->instName = "b";
    this->helpInfo = "TUI-Batch";
    this->argsInfo = "<InstructionsFile>";
}

void InvokeTUIBatch::Execute(std::vector<std::string> &args)
{
    if (cmd != nullptr) {
        cmd->Do(args);
    }
}

void InvokeTUIBatch::SetCommand(std::shared_ptr<Command> &cmd)
{
    InvokeTUIBatch::cmd = cmd;
}
